package com.risk.web.controller.kefu;

import com.risk.common.annotation.Log;
import com.risk.common.core.controller.BaseController;
import com.risk.common.core.domain.AjaxResult;
import com.risk.common.core.page.TableDataInfo;
import com.risk.common.enums.BusinessType;
import com.risk.kernel.domain.KfConfig;
import com.risk.kernel.service.IKfConfigService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author: Liwen
 * @createTime: 2024/11/21
 * @description:
 */

@RestController
@RequestMapping(value = "/kf/")
@Api("客服系统配置管理")
public class KeFuConfigController extends BaseController {

    @Autowired
    private IKfConfigService kfConfigService;

    @ApiOperation("配置sql，分页列表查询")
    @PreAuthorize("@ss.hasPermi('kf:config:list')")
    @GetMapping("/page/list")
    public TableDataInfo list(String keys) {
        startPage();
        List<KfConfig> list = kfConfigService.selectKfConfigList(keys);
        return getDataTable(list);

    }

    /**
     * 新增【sql配置】
     */
    @PreAuthorize("@ss.hasPermi('kf:config:add')")
    @Log(title = "【sql配置】", businessType = BusinessType.INSERT)
    @PostMapping(value = "/add")
    public AjaxResult add(@RequestBody KfConfig kfConfig) {
        kfConfig.setFounder(getUsername());
        return toAjax(kfConfigService.insertKfConfig(kfConfig));
    }


    /**
     * 根据id查询
     */
    @PreAuthorize("@ss.hasPermi('kf:config:query')")
    @GetMapping(value = "getInfo/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(kfConfigService.selectKfConfigById(id));
    }

    /**
     * 修改
     */
    @PreAuthorize("@ss.hasPermi('kf:config:edit')")
    @Log(title = "【客服配置修改】", businessType = BusinessType.UPDATE)
    @PutMapping(value = "edit")
    public AjaxResult edit(@RequestBody KfConfig kfConfig) {
        return toAjax(kfConfigService.updateKfConfig(kfConfig));
    }

    /**
     * 删除
     */
    @PreAuthorize("@ss.hasPermi('kf:config:remove')")
    @Log(title = "【删除】", businessType = BusinessType.DELETE)
    @DeleteMapping("bathRemove/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(kfConfigService.deleteKfConfigByIds(ids));
    }


}
